package com.pfzy.lib.net.subscriber;

import android.app.Activity;
import android.app.Dialog;

import com.pfzy.lib.net.utils.UIUtil;

import io.reactivex.disposables.Disposable;

public abstract class DialogSubscriber<T> extends CCSubscriber<T> {
    private Activity mActivity;
    private Dialog mDialog;

    public DialogSubscriber(Activity activity) {
        super(false);
        this.mActivity = activity;
    }

    public DialogSubscriber(Dialog dialog) {
        super(false);
        this.mDialog = dialog;
    }

    public DialogSubscriber(Activity activity, boolean showErrorToast) {
        super(showErrorToast);
        this.mActivity = activity;
    }

    public DialogSubscriber(Dialog dialog, boolean showErrorToast) {
        super(showErrorToast);
        this.mDialog = dialog;
    }

    @Override
    public void onSubscribe(Disposable d) {
        if (this.mDialog != null) {
            this.mDialog.show();
        } else {
            UIUtil.showLoadingDialog(this.mActivity);
        }
    }

    @Override
    public void onFinish() {
        if (this.mDialog != null) {
            this.mDialog.dismiss();
        } else {
            UIUtil.cancelLoadingDiaoog();
        }
    }
}
